﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace TeamBuy.AccessWebUI
{
    public partial class ActiveUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null && Request.QueryString["Date"] != "" && Request.QueryString["Date"] != null && Request.QueryString["Mail"] != "" && Request.QueryString["Mail"] != null)
            {
                TeamBuy.AccessService.TeamBuyUserService activeUser = new AccessService.TeamBuyUserService();
                DataTable currentUser = activeUser.GetUser(Convert.ToInt32(Common.PublicFunction.DESDecrypt(Request.QueryString["ID"].ToString())));
                if (Convert.ToDateTime(currentUser.Rows[0]["DateCreated"]) == Convert.ToDateTime(Common.PublicFunction.DESDecrypt(Request.QueryString["Date"])) && currentUser.Rows[0]["UserEmail"].ToString() == Common.PublicFunction.DESDecrypt(Request.QueryString["Mail"]))
                {
                    if (activeUser.ActiveUser(Convert.ToInt32(Common.PublicFunction.DESDecrypt(Request.QueryString["ID"].ToString()))) == true)
                    {
                        TeamBuy.AccessService.TeamBuyInviteService activeInvite = new AccessService.TeamBuyInviteService();
                        activeInvite.ActiveInvite(Convert.ToInt32(Common.PublicFunction.DESDecrypt(Request.QueryString["ID"].ToString())));
                        HttpContext.Current.Session["UserID"] = currentUser.Rows[0]["UserID"].ToString();
                        HttpContext.Current.Session["UserEmail"] = currentUser.Rows[0]["UserEmail"].ToString();
                        HttpContext.Current.Session["UserPwd"] = currentUser.Rows[0]["UserPwd"].ToString();
                        HttpContext.Current.Session["UserName"] = currentUser.Rows[0]["UserName"].ToString();
                        HttpContext.Current.Session["CityID"] = currentUser.Rows[0]["CityID"].ToString();
                        HttpContext.Current.Session["CityName"] = currentUser.Rows[0]["CityName"].ToString();
                    }
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
        }
    }
}